package com.photography.controller;

import com.photography.entity.PageResult;
import com.photography.entity.Result;
import com.photography.entity.StatusCode;
import com.photography.pojo.CustomerVo;
import com.photography.pojo.Order;
import com.photography.pojo.OrderVo;
import com.photography.pojo.Product;
import com.photography.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("order")
@CrossOrigin
public class OrderController {

    @Autowired
    private OrderService orderService;


    @GetMapping
    public Result findAll(Order order,
                                     @RequestParam(defaultValue = "1",required = true) Integer page,
                                     @RequestParam(defaultValue = "50",required = true) Integer size){

        PageResult<Order> pageResult  = orderService.findAll(order,page,size);
        return new Result(true, StatusCode.OK, "查询成功",pageResult);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable String id){

        OrderVo orderVo = orderService.getById(id);
        return new Result(true, StatusCode.OK, "查询成功",orderVo);
    }

    @PutMapping
    public Result updateOrder(@RequestBody OrderVo orderVo){
        orderService.updateOrder(orderVo);
        return new Result(true, StatusCode.OK, "更新成功");
    }

    @DeleteMapping
    public Result deleteOrder(@RequestParam String id){
        orderService.deleteOrder(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    @PostMapping
    public Result addOrder(@RequestBody OrderVo orderVo){
        orderService.addOrder(orderVo);
        return new Result(true, StatusCode.OK, "添加成功");
    }

    @PutMapping("/updateOrderByStatus")
    public Result updateOrderByState(@RequestBody Order order){
        orderService.updateOrderByState(order);
        return new Result(true, StatusCode.OK, "修改成功");
    }
//
//    ///order/addserialbyids
//
//    @GetMapping("addserialbyids")
//    public Result addSerialByIds(@RequestParam String[] ids){
//        orderService.addSerialByIds(ids);
//        return Result.ok();
//    }
//
//    @RequestMapping("update")
//    public Result updateOrder(Order order){
//        orderService.updateOrder(order);
//        return Result.ok();
//    }
}
